﻿using System.Windows.Controls;
using ibba.src.noriskbo.ViewModels;

namespace ibba.src.noriskbo
{
    public partial class AppStartup : UserControl
    {
        private AppStartupViewModel _viewModel;

        public AppStartup()
        {
            InitializeComponent();

            _viewModel = (AppStartupViewModel)LayoutRoot.DataContext;            
            _viewModel.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_viewModel_PropertyChanged);
            _viewModel.OnFimProcessamento += new AppStartupViewModel.FimProcessamento(_viewModel_OnFimProcessamento);

            waitPerfil.IsWait = true;
        }

        void _viewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (sender != null)
            {
                switch (e.PropertyName)
                {
                    case "IsWaitPerfil":
                        waitPerfil.IsWait = _viewModel.IsWaitPerfil;
                        break;
                    case "IsWaitProcessamentoRisco":
                        waitProcessamento.IsWait = _viewModel.IsWaitProcessamentoRisco;                        
                        break;
                }
            }
        }
        
        void _viewModel_OnFimProcessamento()
        {
            App.LogIn();
        }

    }
}
